package cn.south.campus.business.controller;

import cn.south.campus.business.model.req.ComplaintReq;
import cn.south.campus.business.model.vo.ComplaintVo;
import cn.south.campus.business.service.ComplaintService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/12/5 13:18
 */
@RestController
@AllArgsConstructor
@RequestMapping("/campus/complaint")
public class ComplaintController {

    private final ComplaintService complaintService;

    @GetMapping("/page")
    public Result<IPage<ComplaintVo>> page(ComplaintReq query) {
        IPage<ComplaintVo> page = complaintService.pageQuery(query);
        return Result.success(page);
    }

    @GetMapping("pageMe")
    public Result<IPage<ComplaintVo>> pageMe(ComplaintReq query) {
        IPage<ComplaintVo> page = complaintService.pageQueryMe(query);
        return Result.success(page);
    }

    @GetMapping("/detail/{id}")
    public Result<ComplaintVo> detail(@PathVariable Long id) {
        ComplaintVo complaintVo = complaintService.detail(id);
        return Result.success(complaintVo);
    }

    @GetMapping("/detailMe/{id}")
    public Result<ComplaintVo> detailMe(@PathVariable Long id) {
        ComplaintVo complaintVo = complaintService.detailMe(id);
        return Result.success(complaintVo);
    }

    @PutMapping("/updateStatus")
    public Result<String> updateStatus(Long id, Integer status) {
        complaintService.updateStatusComplaint(id, status);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        complaintService.deleteComplaint(id);
        return Result.success("删除成功");
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody ComplaintVo complaint) {
        complaintService.addComplaint(complaint);
        return Result.success("添加成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody ComplaintVo complaint) {
        complaintService.updateComplaint(complaint);
        return Result.success("修改成功");
    }

    @PostMapping("agree/{id}")
    public Result<String> agree(@PathVariable Long id) {
        complaintService.agreeComplaint(id);
        return Result.success("点赞成功");
    }

    @PostMapping("disagree/{id}")
    public Result<String> disagree(@PathVariable Long id) {
        complaintService.rejectComplaint(id);
        return Result.success("点踩成功");
    }

    @GetMapping("/pageMyOpt")
    public Result<IPage<ComplaintVo>> pageMyOpt(ComplaintReq query) {
        IPage<ComplaintVo> page = complaintService.pageMyOpt(query);
        return Result.success(page);
    }
}
